<template>
  <div>
    <!-- 初始化 -->
      <FilterTable
        ref="table"
        v-if="isShow"
        :columns="columns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'records'"
        :isSelectColumn="false"
        :onColumnsChange="columns => this.columns = columns"
      >
        <!-- <template slot="controls" slot-scope="props">
          <el-button size="small" type="primary" icon="el-icon-plus" @click="addFun">新增</el-button>
        </template> -->
      </FilterTable>

      <!-- 按钮事件 -->
      <modal v-else :rowData="rowData" :listAllData="listAllData" :isOk="isOk" :type="type" @close="closeHandler"/>
  </div>
</template>

<script>
import { mapState } from 'vuex';
import { dictionary } from '@/utils/dictMixin';
import {getSaleInfo,deleteRole} from '@/api/common/org/gms/saleCompanyMaintain';
import * as types from '@/api/common/org/gms/saleCompanyMaintain/types';
import { getlistAllData} from "@/api/common/org/dealerCompany";
import modal from './modal'
export default {
  name: 'saleCompanyMaintain',
  mixins: [dictionary],
  components: {
    modal
  },
  data() {
    this.BaseTable = null;
    return {
      fetchApi: getSaleInfo,
      fetchParams: { xhrAbort: false },
      columns: this.createTableColumns(),
      isShow: true,
      rowData:'',
      type:'',
      listAllData:[],
      isOk:false,
    };
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text"  onClick={ ()=>this.editFun(props.row) }>
                  编辑
                </el-button>
                <el-divider direction="vertical" />
                <el-button size="mini" type="text" onClick={ ()=>this.showFun(props.row) }>
                  查看
                </el-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '公司代码',
          dataIndex: 'companyCode',
          sorter: true,
          filter: true,
          filterType: 'input',
          // align:"center"
        },
        {
          title: '公司名称',
          dataIndex: 'companyNameCn',
          sorter: true,
          filter: true,
          filterType: 'input',
          // align:"center"
        }
      ];
    },
    getCookie(){
        let allCookie=document.cookie.split(';')
        allCookie.forEach(x=>{
          if(x.indexOf('dataType') > -1 ){
            this.dataType=x.split('=')[1]
            }
        })
        //判断是否为车厂10461003
        console.log(this.dataType,"dataType")
        if(this.dataType == 10461003){
          console.log(this.dataType,"车厂")
        }
      },
    // 新增
    addFun(){
      this.rowData=''
      this.type='add'
      this.isShow=false
    },
    // 编辑
    editFun(row) {
      console.log(row,"编辑")
      this.rowData=row
      this.type='edit'
      this.isShow=false
    },
    // 查看
    showFun(row) {
      console.log(row,"查看")
      this.rowData=row
      this.type='show'
      this.isShow=false
    },
   
    // 关闭
    closeHandler(type) {
      this.isShow = true
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  },
  async mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    this.getCookie()
    await getlistAllData().then(res=>{
      this.listAllData=res.data
      this.isOk=true
    })
  }
};
</script>

<style lang="less" scoped>
</style>
